@include('others.public')

<link rel="stylesheet" href="{{_STA_}}/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form action="" method="post" class="customer-addForm">
    {{csrf_field()}}
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">客户名称</label>
            <div class="layui-input-block">
                <input type="text" name="cus_name" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input" autocomplete="off">
                <tip class="validate-error cus_name" style="display: initial;color: red;"></tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">手机号</label>
            <div class="layui-input-block">
                <input type="number" name="mobile" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input" autocomplete="off">
                <tip class="validate-error mobile" style="display: initial;color: red;"></tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司</label>
            <div class="layui-input-block">
                <input type="text" name="company" placeholder="请输入公司名称" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <input type="text" name="department" placeholder="请输入部门名称" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职位</label>
            <div class="layui-input-block">
                <input type="text" name="position" placeholder="请输入职位名称" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请填写其他备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>

    </div>
</form>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function () {
            $.ajax({
                url:'',
                data:$('.customer-addForm').serialize(),
                type:'post',
                dataType:'json',
                success:function (data) {
                    if(data.status === 'ok'){
                        layer.msg(data.msg,{icon:1,time:1000,shade:0.6},function () {
                            location.reload();
                        })
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000,shade:0.6})
                    }
                },
                error:function (xhr) {
                    var  errors = JSON.parse(xhr.responseText).errors;
                    //方法二
                    $('tip.validate-error').html('');
                    if(errors){
                        for(var i in errors){
                            $('.'+i).text(errors[i][0])
                        }
                    }

                }
            });
            return false;
        });

    });
</script>
</body>
</html>